

from flask import Flask, render_template, request

from apps.pojo.Entity import db

from apps.service.LoginService import LoginService

from apps.controller.UserController import user_bp

app = Flask(__name__)
#注册蓝图对象
app.register_blueprint(user_bp)

#设置数据库
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:12345678@localhost:3306/flask'

app.blueprints

#初始化表
with app.app_context():
    db.init_app(app)
    # db.drop_all()
    # db.create_all()
@app.route('/')
def tologin():
    return render_template('login.html')

@app.route('/login', methods=['POST'])
def index():
    param = request.form
    username = param.get('username')
    password = param.get('password')

    user = LoginService.login(username, password)
    if user:
        return render_template('index.html', user=user)
    else:
        return render_template('login.html', msg='用户名或密码错误')


@app.route("/index_v1")
def index_v1():
    return render_template('index_v1.html')


@app.route("/index_v3")
def index_v3():
    return render_template('index_v3.html')

if __name__ == '__main__':
    app.run()
